package skypeUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


import org.sqlite.SQLiteConfig;
import org.sqlite.SQLiteDataSource;

public class ConnectToSkypeDB {
	
	private Statement statement;
	private Connection connection;
	
	void disconnectFromSkypeDB(){
		try {
			if (connection != null)
				connection.close();
		} catch (SQLException e) {
			// connection close failed.
			System.err.println(e);
		}
	}
	void connectToSkypeDB() throws ClassNotFoundException{
		// load the sqlite-JDBC driver using the current class loader
				Class.forName("org.sqlite.JDBC");

				
				connection=null;;
				try {

					// create a database connection
					SQLiteConfig conf = new SQLiteConfig();
					conf.apply(DriverManager.getConnection("jdbc:sqlite:/home/khodzha/.Skype/mmporubka/main.db"));
					conf.setEncoding(SQLiteConfig.Encoding.valueOf("UTF8"));
					//SQLiteDataSource ds = new SQLiteDataSource();
					//ds.setEncoding("UTF8");
					//ds.setUrl("jdbc:sqlite:C:/Users/chucha/AppData/Roaming/Skype/tuchinandrei/main.db");
					 connection =
					 DriverManager.getConnection("jdbc:sqlite:/home/khodzha/.Skype/mmporubka/main.db");
//					connection = ds.getConnection();
					statement = connection.createStatement();
					statement.setQueryTimeout(100); // set timeout to 100 sec.

					// statement.executeUpdate("drop table if exists person");
					// statement.executeUpdate("create table person (id integer, name string)");
					// statement.executeUpdate("insert into person values(1, 'leo')");
					// statement.executeUpdate("insert into person values(2, 'yui')");
					// ResultSet rs =
					// statement.executeQuery("SELECT * FROM sqlite_master where type='table'")
					
					//ResultSet rs=messagePatternSearch(".*");
					//ResultSet rs=userMessages("pazdnikova_sasha25");
					//ResultSet rs=messageWordSearch("Тест!!!!");
					//ResultSet rs2=messageWordSearch("Тест!!!!");
					//printResultSet(rs);
					//printResultSet(rs2);
					
				} catch (SQLException e) {
					// if the error message is "out of memory",
					// it probably means no database file is found
					System.err.println(e.getMessage());
				}
	}
	public Statement getStatement() {
		return statement;
	}
	public Connection getConnection() {
		return connection;
	}

}
